<!-- 首页 -->
<template>
	<view>
		<view class="reply-box">
			<u-avatar src="http://rbtnet.oss-cn-hangzhou.aliyuncs.com/test/20220608/7f66a8d7c05642c78836db3350a14d41.jpg"></u-avatar>
			<view class="reply-info-box weui-cell">
				<view class="reply-info">
					<view class="nickname">姚淑英</view>
					<view class="reply-text">关注了你</view>
					<view class="reply-time">30天前</view>
				</view>
				<view class="fans-btn">回关</view>
			</view>
		</view>
		
		<view class="reply-box">
			<u-avatar src="http://rbtnet.oss-cn-hangzhou.aliyuncs.com/test/20220608/7f66a8d7c05642c78836db3350a14d41.jpg"></u-avatar>
			<view class="reply-info-box weui-cell">
				<view class="reply-info">
					<view class="nickname">姚淑英</view>
					<view class="reply-text">回关了你</view>
					<view class="reply-time">30天前</view>
				</view>
				<view class="fans-btn">关注</view>
			</view>
		</view>
		
		<view class="reply-box">
			<u-avatar size="100" src="http://rbtnet.oss-cn-hangzhou.aliyuncs.com/test/20220608/7f66a8d7c05642c78836db3350a14d41.jpg"></u-avatar>
			<view class="reply-info-box">
				<view class="reply-info">
					<view class="nickname">姚淑英</view>
					<view class="reply-text">通过动态关注了你</view>
					<view class="reply-time">30天前</view>
				</view>
				<view class="fans-btn">回关</view>
			</view>
		</view>
		
		
		<view class="loadmore-box" v-if="dataList.length > 0">
			<u-loadmore :status="status" @loadmore="load"></u-loadmore>
		</view>
		<u-back-top :scrollTop="scrollTop"></u-back-top>
		<user-auth></user-auth>
	</view>
</template>

<script>
export default {
	data() {
		return {
			status: 'loadmore',
			isEnd: false,
			current: 1,
			pageSize: 10,
			scrollTop: 0,
			dataList: []
		};
	},
	watch: {},
	mounted () {
		this.init();
	},
	methods: {
		init() {
			this.query();
		},
		reload() {
			this.query();
		},
		load() {
			this.loadmore();
		},
		onScrollTop(e) {
			this.scrollTop = e.scrollTop;
		},
		async loadmore() {
			this.status = 'loading';
			if(this.isEnd){
				this.status = 'nomore';
				return;
			}
			var res = await this.getDataList();
			this.dataList = this.dataList.concat(res.data.records);
		},
		query() {
			this.current = 1;
			this.isEnd = false;
			this.status = 'loadmore';
			this.loadquery();
			this.$emit('fresh');
		},
		async loadquery() {
			var res = await this.getDataList();
			this.dataList = res.rows;
			for(var i=0;i<this.dataList.length;i++){
				var data = this.dataList[i];
				data.timestamp = new Date(data.updateTime).getTime();
			}
		},
		async getDataList() {
			var res = await this.$u.get('/im/roomUser/getList', {
				pageNum: this.current,
				pageSize: this.pageSize,
			});
			var totalPage = Math.ceil(res.total/this.pageSize);
			this.pages = totalPage;
			this.current ++;
			this.status = 'loadmore';
			if(this.current > this.pages){
				this.status = 'nomore';
				this.isEnd = true;
			}
			return res;
		},
		chat(item) {
			this.$u.post('/im/roomUser/updateRead',{
				id: item.id
			}).then(res => {
				this.$u.vuex('message', res.data);
				this.$u.route({
					url: 'tn_components/chat/chat',
					params: {
						roomId: item.roomId,
						nickName: item.nickName,
						sendUserId: item.sendUserId
					}
				});
			})
		}
	}
}; 
</script>
<style lang="scss" scoped>
	.user-item {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0 15px;
	}
	.u-image {
		display: flex;
		justify-content: center;
	}
	.user-right {
		padding: 15px;
		padding-left: 15px;
		padding-right: 0;
		flex: 1;
	}
	.user-info {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		margin-bottom: 10px;
	}
	.nickname {
		font-size: 28rpx;
	}
	.time {
		font-size: 26rpx;
		color: #909399;
	}
	.user-content {
		font-size: 26rpx;
		color: #909399;
	}
	.border-bottom {
		position: relative;
	}
	.border-bottom:before {
		content: " ";
		width: 200%;
		height: 200%;
		position: absolute;
		top: 0;
		left: 0;
		border-bottom: 1rpx solid #f4f4f5;
		-webkit-transform: scale(0.5);
		transform: scale(0.5);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		box-sizing: border-box;
	}
	.user-avartar {
		position: relative;
	}
	.online {
		background-color: #fff;
		width: 25rpx;
		height: 25rpx;
		border-radius: 100%;
		border: 2px solid #fff;
		background-color: #DD514C;
		position: absolute;
		bottom: 10rpx;
		right: 4rpx;
	}
	.loadmore-box {
		padding: 10px 0;
	}
	.un-read {
		background-color: red;
		color: #fff;
		padding: 4px;
		font-size: 11px;
		border-radius: 14px;
		height: 15px;
		display: flex;
		align-items: center;
	}
	.tab-btn-box {
		padding: 15px 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.tab-btn {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		flex: 1;
	}
	.tab-btn image{
		width: 50px;
		height: 50px;
	}
	.tab-btn-text {
		margin-top: 5px;
		font-size: 28rpx;
	}
	.tab-btn-dot {
		background-color: #DD514C;
		position: absolute;
		right: 0;
		z-index: 9;
		border-radius: 100%;
		font-size: 10px;
		padding: 20rpx;
		color: #fff;
		height: 10rpx;
		width: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.tab-btn-image {
		position: relative;
	}
	.reply-box {
		display: flex;
		align-items: center;
		padding: 0 30rpx;
	}
	.reply-info-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex: 1;
		margin-left: 30rpx;
		position: relative;
		padding: 15px 0;
	}
	.reply-info {
		padding-right: 40rpx;
		display: flex;
		flex: 1;
		flex-direction: column;
	}
	.nickname {
		font-weight: bolder;
		font-size: 32rpx;
	}
	.reply-text {
		font-size: 32rpx;
		line-height: 44rpx;
		margin-top: 6rpx;
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	.reply-time {
		font-size: 26rpx;
		color: #909399;
		margin-top: 4rpx;
	}
	.fans-btn {
		background-color: #DD514C;
		color: #fff;
		padding: 10rpx 40rpx;
		border-radius: 20px;
		font-size: 30rpx;
		font-weight: bolder;
	}
	.weui-cell:after {
	    content: " ";
	    position: absolute;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    height: 1px;
	    border-bottom: 1px solid #e5e5e5;
	    color: #e5e5e5;
	    -webkit-transform-origin: 0 0;
	    transform-origin: 0 0;
	    -webkit-transform: scaleY(0.5);
	    transform: scaleY(0.5);
	    z-index: 2;//看情况使用
	}
</style>
